home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
034a
/
twview82.zip
/
TEXTDISP.INC
< prev
next >
Wrap
Text File
|
1991-02-04
|
6KB
|
199 lines
procedure SortDistances( var D : distancearray; largest : sector );
var
smallest : dist;
where : sector;
s, t : sector;
begin
for s := 1 to largest - 1 do
begin
smallest := d[s];
where := s;
for t := s + 1 to largest do
if smallest.d > d[t].d then
begin
smallest := d[t];
where := t;
end; {for t}
d[where] := d[s];
d[s] := smallest;
end; {for s}
end; {Sort Distances}
function SetupDistances : boolean;
{ return false if they aborted }
var
s, n : integer;
begin
s := GetSector;
if s <> 0 then
begin
FixDistances( s, distances );
for n := 1 to maxSector do distances[ n ].s := n;
SetUpDistances := true;
end {if}
else
SetUpDistances := false;
end; {SetUpDistances}
function PortNumber( s : sector ) : PortIndex;
{ return the entry into the list of ports corresponding to port s;
return 0 if port not found. }
var
i : portptr;
begin
PortNumber := 0;
if space.Ports.top > 0 then
for i := 1 to space.Ports.top do
if space.Ports.data[ i ].where = s then
PortNumber := i;
end; {PortNumber}
procedure DisplayPort( WhichPort : PortPtr );
begin
if WhichPort = 0 then
writeln('Port data not found!')
else
with space.ports.data[ WhichPort ] do
write( ' F:', amts[ fuel ]:4, ' O:', amts[ organics] : 4, ' E:',
amts[ equipment ] : 4 );
end; {DisplayPort}
function NoteNumber( s : sector ) : integer;
{ return the entry into the list of notes corresponding to sector s;
return 0 if note not found. }
var
i : 1..MaxNote;
begin
NoteNumber := 0;
if space.Ports.top > 0 then
for i := 1 to space.Notes.top do
if space.notes.data[ i ].reference = s then
NoteNumber := i;
end; {PortNumber}
procedure WriteNote( s : sector );
{ print the note associated with sector s }
var
n : 0..MaxNote;
begin
n := NoteNumber( s );
if n = 0 then
write('Missing note! ')
else
write( ' ', space.notes.data[n].info );
end; {write note}
procedure DisplaySector( s : sector; dist : integer );
begin
with space.sectors[s] do
begin
write('Sector ', s:4);
if dist <> Error then
write( ' at distance ', dist : 2 );
if number = UnExplored then
write(' Unexplored sector');
if portType <> NotAPort then
begin
write(' port type ', status( portType ) );
if portType <> Class0 then
DisplayPort( portnumber( s ) );
end; {if port}
if (etc and StarDock) <> Nothing then
write(' Star Dock');
if (etc and HasFighters) <> Nothing then
write(' has fighters');
if (etc and NoteExists) <> Nothing then
WriteNote( s );
writeln;
end; {with}
end; {DisplaySector}
type
WhichStuff = (any, PortOnly, NoteOnly, UnExpOnly );
procedure EliminateUnwanted( var distances : distanceArray;
removeMe : WhichStuff;
var HowManyLeft : integer );
{ Remove the sectors you don't want in the list by pushing them to the back}
var
whichSector : sector;
keep : boolean;
begin
HowManyLeft := 0;
for whichSector := 1 to MaxSector do
begin
case removeMe of
any : keep := distances[ whichSector ].d <> maxint;
PortOnly : keep := space.sectors[whichSector].porttype <> NotAPort;
NoteOnly : keep := space.sectors[whichSector].etc and NoteExists
<> Nothing;
UnExpOnly: keep := (space.sectors[whichSector].number = UnExplored)
and (distances[ whichSector ].d <> maxint);
end; {case}
if keep then
begin
HowManyLeft := HowManyLeft + 1;
distances[ howManyLeft ] := distances[ whichSector ];
end; {if}
end; {for}
write('Total of ', HowManyLeft );
case removeMe of
any : writeln(' sectors from base sector');
PortOnly : writeln(' known ports');
NoteOnly : writeln(' sectors with notes');
UnExpOnly: writeln(' unexplored sectors with known position');
end; {case}
end; {EliminateUnwanted}
procedure FindSmallest( var distances : DistanceArray;
lowest, highest : sector );
{ Examine the distance array from lowest to highest, and move the
sector at smallest distance into the "lowest" slot. }
var
temp : dist;
s,
smallest : sector;
begin
Smallest := lowest;
for s := lowest to highest do
if distances[ s ].d < distances[ smallest ].d then
smallest := s;
temp := distances[ smallest ];
distances[ smallest ] := distances[ lowest ];
distances[ lowest ] := temp;
end; {FindSmallest}
procedure nearestStuff( Filter : WhichStuff );
var
Number,
s, n : integer;
begin
if SetUpDistances then
begin
EliminateUnwanted( distances, filter, Number );
if Number <> 0 then
begin
for n := 1 to Number do
begin
FindSmallest( distances, n, Number );
DisplaySector( distances[ n ].s, distances[n].d );
if n mod 20 = 0 then
if not prompt( 'more? ') then
exit;
end; {for}
end; {if}
end; {if}
end; {nearport}
procedure SortPorts( var NumPorts : integer );
var
s, n : integer;
begin
NumPorts := 0;
if SetUpDistances then
begin
EliminateUnwanted( distances, PortOnly, NumPorts );
writeln('Sorting...');
SortDistances( distances, NumPorts )
end; {if}
end; {SortPorts}